# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from typing import Union


class VoiceEnum:
    XF = "xunfei"
    QWEN = "qwen"
    OPENAI = "openai"
    BROWSER = "browser"

    @classmethod
    def get_logo(cls, code: Union[str, bool] = True):
        """ 语音通道图标 """
        _desc = {
            cls.XF: "static/models/llm_xunfei.png",
            cls.QWEN: "static/models/llm_qwen.png",
            cls.OPENAI: "static/models/llm_openai.png"
        }
        if isinstance(code, bool) and code:
            return _desc
        return _desc.get(code, "")

    @classmethod
    def get_channels(cls, code: Union[str, bool] = True):
        """ 语音通道选项 """
        _desc = {
            cls.BROWSER: "浏览器",
            cls.XF: "讯飞星火",
            cls.OPENAI: "openAi-TTS",
        }
        if isinstance(code, bool) and code:
            return _desc
        return _desc.get(code, "")

    @classmethod
    def get_pronounces(cls, code: Union[str, bool] = True):
        """ 发音人选项 """
        _desc = {
            cls.BROWSER: {
                "utterance": "浏览器自带",
            },
            cls.OPENAI: {
                "alloy": "alloy",
                "echo": "echo",
                "fable": "fable",
                "onyx": "onyx",
                "nova": "nova",
                "shimmer": "shimmer"
            },
            cls.XF: {
                "x4_lingxiaoxuan_oral": "聆小璇",
                "x4_lingfeizhe_oral": "聆飞哲",
                "x4_lingyuzhao_oral": "聆玉昭"
            }
        }
        if isinstance(code, bool) and code:
            return _desc
        return _desc.get(code, "")

    @classmethod
    def get_default_speech(cls, code: Union[str, bool] = True):
        """ 文本转语音默认配置 """
        _desc = {
            cls.BROWSER: {
                "open": 1,
                "name": cls.get_channels(cls.BROWSER),
                "model": "browser",
                "voice": "utterance",
                "speed": 1,   # 0.1~10
                "volume": 1,  # 0~1
                "speed_range": [0.1, 10, 0.1],
                "models": {
                    "browser": "browser"
                },
                "pronounces": cls.get_pronounces(cls.BROWSER)
            },
            cls.XF: {
                "open": 0,
                "name": cls.get_channels(cls.XF),
                "model": "personify",
                "voice": "x4_lingxiaoxuan_oral",
                "speed": 50,   # 0~100
                "volume": 50,  # 0~100
                "speed_range": [10, 100, 1],
                "models": {
                    "personify": "超拟人合成"
                },
                "pronounces": cls.get_pronounces(cls.XF)
            },
            cls.OPENAI: {
                "open": 0,
                "name": cls.get_channels(cls.OPENAI),
                "model": "tts-1",
                "voice": "alloy",
                "speed": 1.0,  # 0.25~4.0
                "volume": 0,   # 无该参数
                "speed_range": [0.25, 4.0, 0.01],
                "agency_api": "",
                "models": {
                    "tts-1": "tts-1",
                    "tts-1-hd": "tts-1-hd"
                },
                "pronounces": cls.get_pronounces(cls.OPENAI)
            }
        }

        if isinstance(code, bool) and code:
            return _desc
        return _desc.get(code, "")

    @classmethod
    def get_default_transfer(cls, code: Union[str, bool] = True):
        """ 语音转文本默认配置 """
        _desc = {
            cls.XF: {
                "name": cls.get_channels(cls.OPENAI),
                "model": "ifasr",
                "models": {
                    "ifasr": "语音转写",
                    "rtasr": "实时语音转写"
                },
            },
            cls.OPENAI: {
                "name": cls.get_channels(cls.OPENAI),
                "model": "whisper-1",
                "agency_api": "",
                "models": {
                    "whisper-1": "whisper-1"
                }
            }
        }

        if isinstance(code, bool) and code:
            return _desc
        return _desc.get(code, "")
